<template>
	<view>
        <u-button type="primary"  text="添加整改结果" @click="add"  v-if="todo!=null && user.Roles.indexOf('施工负责人')>-1"></u-button>
		<u-button type="primary"  text="整改结果审核" @click="show=true" v-if="todo!=null && (user.Roles.indexOf('项目经理')>-1 || user.Roles.indexOf('管理员')>-1)" ></u-button>
		<u--form labelPosition='top'  labelWidth='700rpx' :model="formState" name="basic" layout="horizontal"
			:labelCol="{span:7}" :wrapperCol="{span: 13, offset: 0}">
			<u-collapse :value="['2','3']" ref='coll'>
				<u-collapse-item name="1" title="工程基本信息" icon="https://cdn.uviewui.com/uview/example/cell.png">
				  <buildinfo :buildid='formState.BuildId'></buildinfo>
				</u-collapse-item>
				<u-collapse-item name="2" title="整改" icon="https://cdn.uviewui.com/uview/example/cell.png">
					<u-cell-group>
						<u-cell title="整改原因:" :label="formState.Reason"></u-cell>
						<u-cell title="整改期限(天):" :label="formState.DayLimit"></u-cell>
						<u-cell title="提出人:" :label="formState.UserName"></u-cell>
						<u-cell title="提出时间:" :label="formState.CreateTime"></u-cell>
					</u-cell-group>
					<!-- 	<u-form-item label="工作任务" name="Task" :required="true">
						<u--input v-model="formState.Task" />
					</u-form-item>
					<u-form-item label="关键工序" :required="true" name="KeyStep">
						<u--input v-model="formState.KeyStep" />
					</u-form-item>
					<u-form-item label="测试结果" :required="true" name="TestResult"
						:rules="[{ required: true, message: '请输入值' }]">
						<u--input allow-half v-model="formState.TestResult" :min="0" />
					</u-form-item> -->
				</u-collapse-item>
			
				<u-collapse-item name="3" title="要求整改照片" icon="https://cdn.uviewui.com/uview/example/image.png">
					<u-album :urls="imagesurls"></u-album>
				</u-collapse-item>
				<u-collapse-item name="3" title="整改记录" icon="https://cdn.uviewui.com/uview/example/image.png">
					<u-list>
						<u-list-item v-for="(item, index) in list" :key="index">
							<u-cell v-if="item.ActionName=='施工负责人上传整改结果'" :title="`${item.ActionName}:${item.UserName}${item.CreateTime}`" isLink @click="openpage" :name="item.Id" icon="https://cdn.uviewui.com/uview/example/tag.png">
							</u-cell>
							<u-cell v-else :title="`审核结果：${item.ComeType}:${item.UserName}${item.CreateTime}`" :label="'备注：'+item.Remark" :name="item.Id" icon="https://cdn.uviewui.com/uview/example/tag.png">
							</u-cell>
						</u-list-item>
						<!-- <u-loadmore :status="status" v-if="loading"/> -->
					</u-list>
				</u-collapse-item>
			</u-collapse>
		</u--form>
		<!-- <u-button type="primary" text="保存" @click="save"></u-button> -->
		<u-notify ref="uNotify"></u-notify>
				<u-popup :show="show" :round="10" @close="show=false" mode='center' :customStyle="{width: '500px'}" >
		<u-form :borderBottom='true' labelPosition='left' labelWidth='auto' :model="formState">
		
		
		<u-form-item label="是否通过" name="Result"  borderBottom>
			<!-- <u--input v-model="formState.Task" border="none"/> -->
			
			<u-radio-group v-model="newrecode.ComeType">
						<u-radio
							:customStyle="{marginRight: '16px'}"
					
							label="通过"
							name="通过"
						>
						</u-radio>
						<u-radio
							:customStyle="{marginRight: '16px'}"
											
							label="驳回"
							name="驳回"
						>
						</u-radio>
					</u-radio-group>
		</u-form-item>
				<u-form-item :borderBottom='true' borderBottom label="整改备注" prop="name">
					<u-textarea v-model="newrecode.Remark"></u-textarea>
				</u-form-item>
		<u-button type="primary"  text="提交" @click="check"></u-button>
		
			</u-form>
				</u-popup>
	</view>
</template>

<script>
	import {
		baseUrl
	} from '@/common/config.js'
	import {
		mapGetters
	} from 'vuex'
	import buildinfo from "../c_buildinfo.vue"

	import {
		gettodo,
		getbuildputrightbyid,
		getputrightrecodelist,
		getfilebyoutid,
		GoNext,
	} from '@/common/api.js'
	export default {
		components: {
		  buildinfo
		},
		data() {
			return {
				preid:'2b9a81e9-b2fd-44be-aac7-6afab064092e',
				nextid:'1768a6bb-82dd-4871-87e3-fc6fe25b522c',
				user : JSON.parse(uni.getStorageSync("$userinfo")),
				todo:null,
				coll:[],
				CheckJsonArr: [],
				formState: {}, 
				fileList1: [],
				buildid: null,
				list:[],
				id: null,
				imagesurls: [],
				notifyData: {
					message: '保存成功',
					type: 'success',
					color: '#ffffff',
					bgColor: '',
					fontSize: 15,
					duration: 3000,
					safeAreaInsetTop: false
				},
				show:false,
				newrecode:{},
			}
		},
		onLoad(option) {
			this.buildid = option.buildid
			if (option.id)
			{
				this.id=option.id

				
				
			}

		},
		onShow()
		{
			this.getdate(this.id)
			this.getlist(this.id)
			this.gettodo()
			this.imagesurls=[]
			getfilebyoutid(this.id).then(res=>{
				for(var i =0;i<res.length;i++)
				{
					if(res[i].MyType=='要求整改照片')
					{
						this.imagesurls.push(`${baseUrl}/SysFile/download?id=${res[i].Id}`)
					}
				}
				console.log(this.imagesurls)
				this.$nextTick(() => {
				    this.$refs.coll.init()
				});
			})
		},

		methods: {
			gettodo()
			{
				gettodo(this.id).then(res=>{
					this.todo = res.data
				})
			},
			check()
			{
				GoNext(this.newrecode.ComeType=="通过"?this.nextid:this.preid, this.newrecode.ComeType, this.formState.BuildInfo.ProjManagerId, this.newrecode.Remark, "5", this.formState.Id, this.formState
						.BuildInfo.Name).then(res=>{
							this.show=false
							this.gettodo()
							this.getlist(this.id)
						})
			},
			openpage(e)
			{
				uni.navigateTo({
					url:`resultview?id=${e.name}`
				})
			},
			add(){
				uni.navigateTo({
					url:`resultedit?id=${this.formState.Id}`
				})
			},
			getlist(id)
			{
				getputrightrecodelist(id).then(res=>{
					this.list = res.data
				})
			},
			getdate(id) {
				getbuildputrightbyid(id).then(res => {
					this.formState = res
	                // this.$nextTick(() => {
	                //     this.$refs.coll.init()
	                // });
					setTimeout(()=>{
						this.$refs.coll.init()
					},500)
				})
			},

		}
	}
</script>

<style>
  
</style>
